package club.kingyin.kyblog.core.utils.serialization;

import club.kingyin.kyblog.core.business.dao.web.Focus;
import club.kingyin.kyblog.core.business.dao.web.Site;
import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.ArrayList;

/**
 * @author : kingyins
 * @version : 1.0
 * @program : Ky-Blog
 * @description : 在此处添加类描述
 * @create : 2021年08月16日 10:58
 **/
public class SerTest {

    public static void main(String[] args) {

        ArrayList<Focus> foci = new ArrayList<>();
        Focus f1 = new Focus();
        Focus f2 = new Focus();
        Focus f3 = new Focus();
        f1.setId(1);
        f1.setTitle("山河虽无恙 吾辈当自强");
        f1.setImg("http://cloud.kingyin.club/img/focus/1.jpeg");
        f2.setId(2);
        f2.setTitle("人民有信仰 国家有力量 民族有希望");
        f2.setImg("http://cloud.kingyin.club/img/focus/3.jpeg");
        f3.setId(3);
        f3.setTitle("清澈的爱只为中国");
        f3.setImg("http://cloud.kingyin.club/img/focus/4.jpeg");
        foci.add(f1);
        foci.add(f2);
        foci.add(f3);
        System.out.println(SerializationUtil.serializeAsString(foci));
    }


    public static String jte(Site site) {
        long start = System.currentTimeMillis();
        String s = JSON.toJSONString(site);
        System.out.println(s);
        System.out.println("耗时："+(System.currentTimeMillis() - start));
        return s;
    }

    public static void jtd(String s) {
        long start = System.currentTimeMillis();
        Site site = JSON.parseObject(s, Site.class);
        System.out.println(site);
        System.out.println("耗时："+(System.currentTimeMillis() - start));
    }

    public static String ste(Site site) {
        long start = System.currentTimeMillis();
        String s = SerializationUtil.serializeAsString(site);
        System.out.println(s);
        s = DigestUtils.md5Hex(s);
        System.out.println("耗时："+(System.currentTimeMillis() - start));
        return s;
    }

    public static void std(String s) {
        long start = System.currentTimeMillis();
        Site site = SerializationUtil.deserialize(s,Site.class);
        System.out.println(site);
        System.out.println("耗时："+(System.currentTimeMillis() - start));
    }
}
